package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlw.hr_man.Model.EmployeeModel;
import com.hlw.hr_man.service.AskForLeaveService;
import com.hlw.hr_man.serviceImpl.AskForLeaveServiceImpl;

public class HasApplyAflController extends HttpServlet{

	/**
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
	 */ 
	private static final long serialVersionUID = 1L;
	
	AskForLeaveService aflService = new AskForLeaveServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		if(req.getSession().getAttribute("loginEmployee")!=null){
		//得到当前登录用户
		EmployeeModel employee = (EmployeeModel) req.getSession().getAttribute("loginEmployee");
		//得到当前用户的角色id
		int role_id = employee.getRole_id();
		//获得当前用户id
		int e_id = employee.getE_id();
		PrintWriter pw = resp.getWriter();
		if (role_id == 7 || role_id == 1) {
			String s = null;
			try {
				s = req.getServletContext().getAttribute("msg").toString();
			} catch (Exception e) {
				// TODO: handle exception
			}
			if (s != null) {
				pw.write("1");
				req.getServletContext().removeAttribute("msg");
			} else {
				pw.write("0");
			}
		} else {
			String str = null;
			String id = String.valueOf(e_id);
			try {
				str = req.getServletContext().getAttribute(id).toString();
				System.out.println(str);
			} catch (Exception e) {
				str = null;
			}
			if (str != null) {
				pw.write("2");
				req.getServletContext().removeAttribute(id);
			} else {
				pw.write("0");
			}
		}
		}
	}
}
